<?php

namespace App\Model;

use App\BaseModel;

class ProductSku extends BaseModel
{
    protected $table = "product_skus";

    protected $fillable = [
        'skuCode',
        'product_id',
        'attr_group_id',
        'origin_price',
        'price',
        'point_price',
        'price_3_4',
        'price_5',
        'sku',
        'desc',
        'user_id',
        'creator',
        'updater',
    ];

    public function beforeSave($input = null)
    {
        $this->consume_price = 0.9*$this->price;
        return true;
    }

    public function product()
    {
        return $this->belongsTo('App\Model\WineProduct','product_id','id');
    }

    public function groupAttr()
    {
        return $this->belongsTo('App\Model\ProductAttrGroup','attr_group_id','id');
    }

    public function skuAttr()
    {
        return $this->hasMany('App\Model\ProductSkuAttr','product_sku_id','id');
    }
}
